package com.jfeat.am.module.wegou.api.shop.crud;

import com.jfeat.am.common.constant.tips.SuccessTip;
import com.jfeat.am.common.constant.tips.Tip;
import com.jfeat.am.common.controller.BaseController;
import com.jfeat.am.module.wegou.constant.Identify;
import com.jfeat.am.module.wegou.services.crud.filter.ProductStoreFilter;
import com.jfeat.am.module.wegou.services.crud.service.ProductStoreService;
import com.jfeat.am.module.wegou.services.domain.model.ProductStoreModel;
import com.jfeat.am.module.wegou.services.persistence.model.ProductStore;
import com.jfeat.am.module.wegou.services.persistence.model.RestaurantTag;
import com.jfeat.am.module.wegou.services.persistence.model.TagManage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api("料理店铺（料理店铺使用）")
@RestController
@RequestMapping("/api/shop/product-store")
public class ProductStoreForShopEndpoint extends BaseController {

    @Resource
    ProductStoreService productStoreService;

    @ApiOperation(value = "料理店铺 返回当前登录者料理店铺信息", response = ProductStore.class)
    @GetMapping("/myRestaurant")
    @com.jfeat.am.module.wegou.annotation.UserIdentity("STORE")
    public Tip getMyProductRestaurant() {
        ProductStore productRestaurant = getAttr(Identify.PRODUCT_STORE);
        ProductStoreModel productStoreModel = productStoreService.showRestaurant(productRestaurant.getId());
        return SuccessTip.create(productStoreModel);
    }

    /*@ApiOperation(value = "料理店铺 返回当前登录者料理店铺信息", response = ProductStore.class)
    @GetMapping("/myCanteen")
    @com.jfeat.am.module.wegou.annotation.UserIdentity("STORE")
    public Tip getMyProductCanteen() {
        ProductStore productRestaurant = getAttr("productStore");
        ProductStoreModel productStoreModel = productStoreService.showRestaurant(productRestaurant.getId());
        return SuccessTip.create(productStoreModel);
    }*/

    @ApiOperation(value = "料理店铺 修改料理店铺信息", response = ProductStore.class)
    @PutMapping("/myRestaurant")
    @com.jfeat.am.module.wegou.annotation.UserIdentity("STORE")
    public Tip updateProductRestaurant(@RequestBody ProductStoreModel entity) {
        ProductStore productRestaurant = getAttr(Identify.PRODUCT_STORE);
        entity.setId(productRestaurant.getId());
        List<TagManage> tagManages = entity.getTags();
        for (TagManage tagManage : tagManages) {
            RestaurantTag restaurantTag = new RestaurantTag();
            restaurantTag.setStoreId(entity.getId());
            restaurantTag.setTagId(tagManage.getId());
            entity.getRestaurantTags().add(restaurantTag);
        }
        return SuccessTip.create(productStoreService.updateMaster(entity, new ProductStoreFilter(), null, null));
    }

    /*@ApiOperation(value = "商户店铺 修改商户店铺信息", response = ProductStore.class)
    @PutMapping("/myCanteen")
    @com.jfeat.am.module.wegou.annotation.UserIdentity("STORE")
    public Tip updateProductCanteen(@RequestBody ProductStoreModel entity) {
        ProductStore productRestaurant = getAttr("productStore");
        entity.setId(productRestaurant.getId());
        List<TagManage> tagManages = entity.getTags();
        for (TagManage tagManage : tagManages) {
            RestaurantTag restaurantTag = new RestaurantTag();
            restaurantTag.setStoreId(entity.getId());
            restaurantTag.setTagId(tagManage.getId());
            entity.getRestaurantTags().add(restaurantTag);
        }
        return SuccessTip.create(productStoreService.updateMaster(entity, new ProductStoreFilter(), null, null));
    }*/
}
